var arr = [1, 2, [3, 4, 5, [6, 7, 8], 9], 10, [11, 12]];
//输出
// [1,2,3,4,5,6,7,8,9,10,11,12]

// method 1 ============================================
function flat(arr) {
    if (Object.prototype.toString.call(arr) != "[object Array]") {
        return false
    };
    let res = [];
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] instanceof Array) {
            res = res.concat(flat(arr[i]))
        } else {
            res.push(arr[i])
        }
    }
    return res;
};
var arr = [1, 2, [3, 4, 5, [6, 7, 8], 9], 10, [11, 12]];
flat(arr);
//[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

// method 2 ============================================
function flat(arr){
	if(Object.prototype.toString.call(arr) != "[object Array]"){return false};
	let res=[];
    arr.map(item=>{
        if(item instanceof Array){
            res.push(...item);//展开数组[11,12] 为11,12
        }else{
            res.push(item)
        }
    });
    return res;
};	
var arr = [1,2,[3,4,5,[6,7,8],9],10,[11,12]];
flat(arr);
//[1, 2, 3, 4, 5, Array(3), 9, 10, 11, 12]

// method 3 ============================================
function flat(arr){
	if(Object.prototype.toString.call(arr) != "[object Array]"){return false};
	let res=[];
    arr.map(item=>{
        if(item instanceof Array){
            res.push(...flat(item));
        }else{
            res.push(item)
        }
    });
    return res;
};	
var arr = [1,2,[3,4,5,[6,7,8],9],10,[11,12]];
flat(arr);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

// method 4 ============================================
function flat(arr){
	if(Object.prototype.toString.call(arr) != "[object Array]"){return false};
	
	let res = arr.reduce((prev,cur)=>{
	    return prev.concat(Array.isArray(cur) ? flat(cur) : cur)
	},[])
	return res;
};
var arr = [1,2,[3,4,5,[6,7,8],9],10,[11,12]];
flat(arr);

// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

// method 5 ============================================
[1,2,[3]].flat()
// [1, 2, 3]

[1,2,[3,[4]]].flat(2)
// [1, 2, 3, 4]

// method 6 ============================================
// method 7 ============================================
// method 8 ============================================